﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using Portal.Xml.Utility;
using System.Collections.ObjectModel;

namespace Portal.Systems.Model
{
    public class PageZoneCls
    {
        public string PageZoneId;
        public string ZoneAlias;
        public string ZoneName;
        public string AssetCode;
        public string DataLanguage;
        public string PageId;
        public int Active;
        public int SortIndex;
        public Collection<PageZoneModuleCls> PageZoneModules = new Collection<PageZoneModuleCls> { };
    }

    public class PageZoneParser
    {
        public static PageZoneCls CreateInstance()
        {
            //tao 1 class trang....
            PageZoneCls oPageZoneCls = new PageZoneCls();
            return oPageZoneCls;
        }

        public static PageZoneCls ParseFromXml(string XmlData)
        {
            DataSet ds = XmlUtility.GetDataSetFromXml(XmlData);
            PageZoneCls oPageZoneCls = ParseFromDataRow(ds.Tables[0].Rows[0]);
            return oPageZoneCls;
        }


        public static PageZoneCls ParseFromDataRow(DataRow dr)
        {
            PageZoneCls OPageZoneCls = new PageZoneCls();
            OPageZoneCls.PageZoneId = XmlUtility.GetString(dr, "PageZoneId", true);
            OPageZoneCls.ZoneAlias = XmlUtility.GetString(dr, "ZoneAlias", true);
            OPageZoneCls.ZoneName = XmlUtility.GetString(dr, "ZoneName", true);
            OPageZoneCls.AssetCode = XmlUtility.GetString(dr,"AssetCode",true);
            OPageZoneCls.DataLanguage = XmlUtility.GetString(dr, "DataLanguage", true);
            OPageZoneCls.Active = XmlUtility.GetInt(dr, "Active",true);
            OPageZoneCls.SortIndex = XmlUtility.GetInt(dr, "SortIndex", true);
            OPageZoneCls.PageId = XmlUtility.GetString(dr, "PageId", true);
            return OPageZoneCls;
        }

        public static PageZoneCls[] ParseFromDataTable(DataTable dtTable)
        {
            PageZoneCls[] PageZones = new PageZoneCls[dtTable.Rows.Count];
            for (int iIndex = 0; iIndex < dtTable.Rows.Count; iIndex++)
            {
                PageZones[iIndex] = ParseFromDataRow(dtTable.Rows[iIndex]);
            }

            return PageZones;
        }
    }
}


